﻿using System;
using System.Collections.Generic;
using Microsoft.Commerce.Broker;
using Microsoft.Commerce.Contracts;
using Microsoft.Commerce.Contracts.Messages;
using Microsoft.Commerce.Providers.Components;
using System.Linq;

namespace MusicWorks.Service.Extensions.Components
{
    public class CatalogEntitySolrSearchProcessor : OperationSequenceComponent
    {
        //private CommerceQueryOperation _queryOperation;
        private CommerceCatalogFullTextSearch _search;
        private static string[] _supportedModels = new[] {"CatalogEntity","Product", "Variant"};

        public override void ExecuteQuery(CommerceQueryOperation queryOperation, OperationCacheDictionary operationCache,
                                          CommerceQueryOperationResponse response)
        {
            
            //Get search criteria
            _search = (CommerceCatalogFullTextSearch) queryOperation.SearchCriteria;
           
            if (!_supportedModels.Contains(queryOperation.Model.ModelName))
                throw new Exception("Invalid model provided");

            foreach (var entity in GetSearchResults())
            {
                response.CommerceEntities.Add(entity); 
            }
                
        }

        public List<CommerceEntity> GetSearchResults()
        {
            var results = new List<CommerceEntity>();
            return results;
        }


        //private CommerceQueryOperation _queryOperation;
        //private List<EntityMapping> _returnModelMappings;
        //private string _returnModelName;
        //private CommerceCatalogFullTextSearch _search;
        //private static string[] _supportedModels;


        //static CatalogEntityFullTextSearchProcessor();
        //public CatalogEntityFullTextSearchProcessor();
        //private CatalogSearch GetCatalogSearch(CommercePropertyCollection propertiesToReturn);
        //private List<CommerceEntity> GetSearchResults(out int? totalRecordCount);
        //private bool Init(CommerceQueryOperation queryOperation);
        //private void SetEntityMappings();
        //private void SetReturnModel();
        //private void SetSearchOptionsClassTypes(CatalogSearchOptions searchOptions);
        //private void ValidateSearch();
        //private void ValidateTypeToSearch();
    }
}
